/**
 *
 */
package com.storm.lib.bean.template;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;


import org.springframework.flex.roo.addon.asdt.core.internal.antlr.AS3Parser.continueStatement_return;

import com.storm.lib.type.TemplateType;
import com.storm.lib.util.ExceptionUtil;
import com.storm.lib.util.FileUtil;


/**
 * 类功能: 所有模板类的基类
 * @author johnny
 * @version 2010-10-28
 */
public class BaseTemplate {
	/**
	 * 替换量映射方式
	 */
	private HashMap<String, String> params = new HashMap<String, String>();
	/**
	 *模板文件
	 */
	private File templateFile;


	/**
	 * @return the params
	 */
	private HashMap<String, String> getParams() {
		return params;
	}


	/**
	 * @param params the params to set
	 */
	private void setParams(HashMap<String, String> params) {
		this.params = params;
	}


	/**
	 * @return the templateFile
	 */
	public File getTemplateFile() {
		return templateFile;
	}


	/**
	 * @param templateFile the templateFile to set
	 */
	public void setTemplateFile(File templateFile) {
		this.templateFile = templateFile;
	}

	/**
	 *
	 * 方法功能:获取模板String
	 * 更新时间:2010-10-28, 作者:johnny
	 */
	public String getTemplateStr(){
		String result = FileUtil.getFileStrByTag(getTemplateFile(),TemplateType.TEMPLATE_START_TAG);
//		Set keys=params.keySet();
		Iterator iter = params.entrySet().iterator();
		while (iter.hasNext()) {
			Map.Entry entry = (Map.Entry) iter.next();
			String key = (String) entry.getKey();
			String val = (String) entry.getValue();
			result = result.replaceAll("\\{\\{"+key+"\\}\\}", val);
		}
		return result;
	}

	/**
	 *
	 * 方法功能:设置hashkey参数
	 * 更新时间:2010-10-28, 作者:johnny
	 * @param paramName
	 * @param value
	 */
	public void setParam(String paramName,String value){
		this.getParams().put(paramName, value);
	}
}
